<?php

trait Trait_Api_Comment
{


    /**
     * @function 随机设置评论时间
     * @return string
     */
    private function random_pl_time()
    {
        $hour = mt_rand(0, 3);
        $minute = mt_rand(0, 60);
        $second = mt_rand(0, 60);
        $elapse = '';
        $unitArr = array(
            '年' => 'year',
            '个月' => 'month',
            '周' => 'week',
            '天' => 'day',
            '小时' => 'hour',
            '分钟' => 'minute',
            '秒' => 'second'
        );
        foreach ($unitArr as $cn => $u)
        {
            if ($$u > 0)
            {
                $elapse = $$u . $cn;
                break;
            }
        }
        return $elapse . '前';
    }

    //获取评论的汇总信息
    private  function get_comment_count($typeid, $article_id, $satisfyscore)
    {
        $pic_num = DB::select()->from('comment')
            ->where('isshow','=', 1)
            ->and_where('typeid','=', $typeid)
            ->and_where('articleid','=', $article_id)
            ->and_where('level','>=', 1)
            ->and_where('level', '<=', 5)
            ->and_where(DB::expr(" AND LENGTH(TRIM(piclist))>0"))
            ->execute()
            ->count();
        $rtn['picnum'] = $pic_num;
        //计算等级
        $rtn = array_merge($rtn, St_Functions::get_satisfy($typeid, $article_id, $satisfyscore, array('isAll' => 1)));
        return $rtn;
    }




}